package cate.game.display.msg;

import cate.common.rpc.path.RpcCommonPath;
import cate.game.GameBody;
import cate.game.client.ClientContext;
import cate.game.client.msg.ClientMsg;
import cate.game.client.msg.MsgConfig;
import cate.game.client.msg.MsgInput;
import cate.game.client.msg.id.MsgIdBDisplay;
import cate.game.display.cmd.WatchHeroCmd;
import cate.game.display.po.HeroDisplay;
import easy.java.dev.note.NoteField;

import java.util.Optional;

@ClientMsg(title = "英雄展示获取 の 请求")
public class HeroDisplayGetReq implements MsgInput {

    @NoteField(value = "英雄展示的唯一ID")
    public String displayUid;

    @NoteField("玩家区服id")
    public int srvId;

    @Override
    public void execute(GameBody game, ClientContext cc) {
        if (srvId == cc.getRole().getBase().srvId) {
            Optional<HeroDisplay> opt = game.facilities.getMongo().heroDisplay.findById(this.displayUid);
            if (opt.isPresent()) {
                HeroDisplayGetResp resp = new HeroDisplayGetResp();
                resp.display = opt.get();
                cc.sendNow(resp);
                return;
            }
        } else {
            WatchHeroCmd cmd = new WatchHeroCmd();
            cmd.srvId = srvId;
            cmd.displayUid = displayUid;
            cmd = game.rpcSend().requestResponseGame(RpcCommonPath.WATCH_HERO_G2G, srvId, cmd, WatchHeroCmd.class);
            if (cmd.data != null) {
                cc.sendNow(cmd.data);
                return;
            }
        }
        game.notice.message(cc.getRole(), "该英雄展示已过期");
    }

    @Override
    public MsgConfig conf() {
        return MsgIdBDisplay.HERO_DISPLAY_GET_REQ;
    }
}
